package com.exam.zwl;

import com.exam.common.pojo.BaseTopic;
import com.exam.common.pojo.TestPaper;
import com.exam.common.service.IBaseTopicService;
import com.exam.common.service.ITestPaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/onlineExam")
public class ZwlContrller {
    @Autowired
    ITestPaperService testPaperService;

    @Autowired
    IBaseTopicService baseTopicService;

    @PostMapping("/selectName")
    public HashMap<String,Object> selectName(){
        return testPaperService.selectName("exam01");
    }

    @GetMapping("/selectTopic")
    public List<BaseTopic> selectTitle(){
        HashMap<String, Object> map = testPaperService.selectName("exam01");
        List<TestPaper> list = (List<TestPaper> )map.get("list");

        String baseTopic="";
        int shortTopic=0;
        for (TestPaper testPaper : list) {
           baseTopic=testPaper.getBaseTopic();
           shortTopic=testPaper.getShortTopic();
        }
        String[] split = baseTopic.split(",");
        int[] arr = Arrays.stream(split).mapToInt(Integer::parseInt).toArray();
        Integer newNums[] = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        HashMap<String, Object> map1 = baseTopicService.selectTopic(newNums);
        List<BaseTopic> list1=(List<BaseTopic> )map1.get("list");

        for (BaseTopic topic : list1) {
            System.out.println(topic);
            System.out.println(topic);
        }
        return list1;
    }
}
